<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use Alipay\lib\AlipayNotify;
use Des3\DES3;
use app\api\service\Common;

class Index extends Controller{
    public function index() {
        $this->redirect('/wechat/member/index');


//          $a=array("a"=>"Dog","b"=>"Cat","c"=>"Horse");
//          print_r(array_rand($a,3));
//        $data = strtotime(date('Y-m-d')) - 60 * 60 * 24 * 90;
//        echo date('y-m-d', $data);
        //return view();
//        $data = Common::get_region(['region_id' => 0]);
//        dump($data);
//        // 开始实名认证
//        $host = "http://lundroid.market.alicloudapi.com";
//        $path = "/lianzhuo/verifi";
//        $method = "GET";
//        $appcode = "23b6b7fe2b9840168b2ce4bfe06c2075";
//        $headers = array();
//        array_push($headers, "Authorization:APPCODE " . $appcode);
//        $querys = 'acct_pan=6214467873116896306';
//        $querys .= '&phone_num=15802571830';
//        $querys .= '&acct_name=罗狮龙1';
//        $querys .= '&cert_id=43038119890623231X';
//        $bodys = "";
//        echo $url = $host . $path . "?" . $querys;
//
//        $curl = curl_init();
//        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
//        curl_setopt($curl, CURLOPT_URL, $url);
//        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//        curl_setopt($curl, CURLOPT_FAILONERROR, false);
//        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//        curl_setopt($curl, CURLOPT_HEADER, true);
//        if (1 == strpos("$".$host, "https://"))
//        {
//            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
//        }
//        $rs =  curl_exec($curl);
//        $rs = substr($rs, strpos($rs, '{'));
//        $rs = json_decode($rs, true);
//        dump($rs);
        //return view();
//        echo strtotime(date('Y-m-d'));
//        echo '<br />';
//        echo strtotime('2017-01-02 00:00:00');
//        echo '<br />';
//        echo date('w');
//        exit;
//        $obj = (object) "Hello, everyone";
//        dump($obj);exit;
//        $model = 'order_server';
//        $order_status = 1;
//        if (!($model == 'order_buy' && $order_status == 1) && !($model == 'order_server' && $order_status == 2)) {
//            echo 123;
//            //return ['data'=>'','code'=>400057,'msg'=> 'FAULT']; // 订单模型错误
//        }
//        exit;
//        Db::listen(function($sql, $time, $explain){
//            // 记录SQL
//            echo $sql. ' ['.$time.'s]';
//            // 查看性能分析结果
//            dump($explain);
//        });
//        $start_time = 1479370846;
//        $end_time = 1481163586;
//        $member_money = db('interface_request_log')->where(function ($query) use($start_time, $end_time) {
//            $query->where('request_time', 'between time',[$start_time, $end_time]);
//        })->select();
//
//        dump($member_money);
//        exit;
//        if($member_money) {
//            return ['data'=>$member_money,'code'=>200,'msg'=> '获取用户账单成功'];
//        } else{
//            return ['data'=>'','code'=>0,'msg'=> '获取用户账单失败'];
//        }


//        $alipay_config = config('alipay_config');
//        $alipayNotify = new AlipayNotify($alipay_config);
//        $verify_result = $alipayNotify->verifyNotify();
//        dump($verify_result);
//        echo 123;exit;
//        $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
//        $a2=array("e"=>"red","f"=>"black","g"=>"purple");
//        $a3=array("a"=>"red","b"=>"black","h"=>"yellow");
//
//        $result=array_diff($a2,$a1,$a3);
//        print_r($result);
//        if (!is_file(DATA_PATH . 'install.lock')) {
//            $this->redirect('install/Index/index');
//        }

        //$view = new \think\View();

        //return view();
    }

    public function getAround(){
        $lat = 116.872774;
        $lon = 28.211628;
        $PI = 3.14159265;
        $raidus = 1000;
        $latitude = $lat;
        $longitude = $lon;

        $degree = (24901*1609)/360.0;
        $raidusMile = $raidus;

        $dpmLat = 1/$degree;
        $radiusLat = $dpmLat*$raidusMile;
        $minLat = $latitude - $radiusLat;
        $maxLat = $latitude + $radiusLat;

        $mpdLng = $degree*cos($latitude * ($PI/180));
        $dpmLng = 1 / $mpdLng;
        $radiusLng = $dpmLng*$raidusMile;
        $minLng = $longitude - $radiusLng;
        $maxLng = $longitude + $radiusLng;
        echo $minLat."#".$maxLat."@".$minLng . "#".$maxLng;
    }

    public function test()
    {
        dump( base64_decode('8 WQh0EugPywASdOk121qg'));
        $des = new DES3();
        //echo $des->encrypt('15116463033');
        exit;
        $param = [
            'phone' => $des->encrypt('13611425049'),
            'password' => $des->encrypt('123456'),
            'type' => 1
        ];
        $param = json_encode($param);
        //echo '<br />';
        $time = time();
        $sgin = md5('timestamp=' .$time . '&key=jgsdfjkfgjs#$%&khs2423hkfh');
        $url = 'http://localhost:8099/index.php/interface/login?timestamp=' . $time . '&member_ip=127.0.1.1&sign=' . $sgin . '&member_id=1&page=2&data=' . $param;
        $data = get_data($url);

        //$data = post_data($url, $param);

        dump($data);
        dump($data = json_decode($data, true));
        //$data= $data['data']['data'];
        dump($data);
        exit;
    }
}